home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / LINE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  1.0 KB  |  42 lines

  1.                                             /* line.c   ( rectangle ) */
  2.                                  /* Entered by A. Wayner */
  3.  
  4. # include <graphics.h>
  5. # include <stdlib.h>
  6.  
  7. main()
  8. {
  9.     int graphdriver = DETECT;
  10.     int graphmode, x1, x2, y1, y2, maxx, maxy, maxcolor;
  11.  
  12.                                             /* Detect adapter type and    */
  13.                                             /* initialize graphics system */
  14.       initgraph( &graphdriver, &graphmode, "\\turboc");
  15.     outtextxy( 10, 10, "Random lines with 'line' ");
  16.  
  17.     maxx = getmaxx() - 100;
  18.     maxy = getmaxy() - 60;
  19.     maxcolor = getmaxcolor();
  20.     randomize();                        /* Initialize random number generator */
  21.  
  22.                                             /* Exit when user presses a key */
  23.     outtextxy( 10, getmaxy() - 30,"Press any key to exit : ");
  24.     while( !kbhit())
  25.     {
  26.                                             /* Generate random end points  */
  27.                                             /* for the lines */
  28.         x1 = random( maxx ) + 50;
  29.         x2 = random( maxx ) + 50;
  30.         y1 = random( maxy ) + 30;
  31.         y2 = random( maxy ) + 30;
  32.  
  33.         setcolor( WHITE );
  34.  
  35.                                             /* Now draw the line */
  36.         line( x1, y1, x2, y2 );
  37.     }
  38.  
  39.     closegraph();                        /* Exit graphics library */
  40.  
  41. }
  42.